﻿// $Id$
/*! \file
 * \brief Definition of Northwind.DomainModel.OrderDetails.
 *
 * \author $Author$
 * \date $Date$
 * \version $Revision$
 */

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Xml.Serialization;
using Salamanca.DataAccess;
using Salamanca.DataAccess.Collections;
using Salamanca.DataRules;
#if (!NET_CF)
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;
#endif

namespace Northwind.DomainModel
{



    ///////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ///////////////////////////////////////////////////////////////////////////

    public partial interface IOrderDetailsContainer
    {
    }



    ///////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ///////////////////////////////////////////////////////////////////////////

    public partial interface IOrderDetailsMapper:
        IDataMapper
    {
        /// <summary />
        DomainModelKeyedCollection<OrderDetails> FindByOrder(Order order, DataMapperCollection dataMappers);
    }



    ///////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ///////////////////////////////////////////////////////////////////////////

#if (!NET_CF)
    [Serializable]
    [DataObject]
#endif
    public partial class OrderDetails:
        DomainModel<OrderDetails.PrimaryKey, OrderDetails.DataTransfer>
    {

        /// <summary />
#if (!NET_CF)
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class PrimaryKey:
            PrimaryKey<PrimaryKey.Key>
        {

            /// <summary />
            public PrimaryKey():
                base()
            {
            }

            /// <summary />
            public PrimaryKey(PrimaryKey.Key key):
                base(key)
            {
            }

        }

        /// <summary />
        [SoapType("OrderDetailsData", "http://www.codeplex.com/salamanca/northwind/domainmodel/")]
        [XmlType("OrderDetailsData", Namespace="http://www.codeplex.com/salamanca/northwind/domainmodel/")]
#if (!NET_CF)
        [Serializable]
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class DataTransfer:
            IDataTransferObject
        {
        }

        /// <summary />
        public OrderDetails():
            base()
        {
        }

        /// <summary />
        public OrderDetails(DataMapperCollection dataMappers):
            base(dataMappers)
        {
        }

#if (!NET_CF)
        /// <summary />
        protected OrderDetails(SerializationInfo info, StreamingContext context):
            base(info, context)
        {
        }
#endif

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            if (_Product!=null)
              ((IPersistent)_Product).Save(e.Context);
            if (_Order!=null)
              ((IPersistent)_Order).Save(e.Context);

            base.OnSaving(e);
        }

        /// <summary />
        public override void Load(bool lazyLoad)
        {
            base.Load(lazyLoad);

            if (!IsNew)
            {
                _LoadProduct(lazyLoad);
                _LoadOrder(lazyLoad);
            }
        }

        /// <summary />
        public override void Unload()
        {
            base.Unload();

            _Product=null;
            _Order=null;
        }

        /// <summary />
        public static IList<OrderDetails> FindByOrder(Order order, DataMapperCollection dataMappers)
        {
            return ((IOrderDetailsMapper)dataMappers[typeof(OrderDetails)]).FindByOrder(order, dataMappers);
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Product Product
        {
            get
            {
                return _ProductProperty;
            }
            set
            {
                if (_ProductProperty!=value)
                {
                    _ProductProperty=value;
                    RaisePropertyChanged("Product");
                }
            }
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Order Order
        {
            get
            {
                return _OrderProperty;
            }
            set
            {
                if (_OrderProperty!=value)
                {
                    _OrderProperty=value;
                    RaisePropertyChanged("Order");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public decimal? UnitPrice
        {
            get
            {
                return _UnitPriceProperty;
            }
            set
            {
                if (_UnitPriceProperty!=value)
                {
                    _UnitPriceProperty=value;
                    RaisePropertyChanged("UnitPrice");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public short? Quantity
        {
            get
            {
                return _QuantityProperty;
            }
            set
            {
                if (_QuantityProperty!=value)
                {
                    _QuantityProperty=value;
                    RaisePropertyChanged("Quantity");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public float? Discount
        {
            get
            {
                return _DiscountProperty;
            }
            set
            {
                if (_DiscountProperty!=value)
                {
                    _DiscountProperty=value;
                    RaisePropertyChanged("Discount");
                }
            }
        }

    }
}
